package fastjsonDemo.JSONArrayDemo;

import com.alibaba.fastjson.JSONArray;
import org.junit.Test;

import java.util.Date;
import java.util.HashMap;

public class demo1 {
	//相当于List<Object>
	static JSONArray jsonArray;

	static {
		HashMap<String, Object> map = new HashMap<>();
		map.put("AAA", "aaa");
		map.put("BBB", "bbb");

		HashMap<String, Object> map2 = new HashMap<>();
		map2.put("AAA", "aaa");
		map2.put("BBB", "bbb");

		jsonArray = new JSONArray();
		jsonArray.add(map);
		jsonArray.add(map2);
		jsonArray.add(1);
		jsonArray.add(new Date());
	}

	@Test
	public void ceui() {


		/*转成数组*/
		Object[] objects = jsonArray.toArray();

		//转json
		String jsonString = jsonArray.toJSONString();

		System.out.println("jsonString = " + jsonString);
		//输出[{"AAA":"aaa","BBB":"bbb"},{"AAA":"aaa","BBB":"bbb"},1,1567146298105]

	}

	/**
	 * json字符串 转成 jsonArray
	 */
	@Test
	public void c_2() {

		String dataSource = "[{\"valueId\":\"315380125975958501\",\"valueText\":\"black\",\"propertyText\":\"zjj1215\",\"propertyId\":\"315380088302719245\"}]";
		System.out.println("dataSource = " + dataSource);
		JSONArray objects = JSONArray.parseArray(dataSource);
		System.out.println("objects = " + objects);


	}


}
